#include "SquareIndicator.h"
#include "Units.h"
#include "Snapping.h"
#include <osgManipulator/Projector>
#include <QtCore/QPoint>
#include <osg/ShapeDrawable>


SquareIndicator::SquareIndicator()
{
	m_rIndicatorTransform = createIndicator();
}


void SquareIndicator::setMousePosition(const QPoint& point, osg::Camera* camera)
{
	osg::Vec3 p = Snapping::projectMouseToGroundPlane(osg::Vec2(point.x(), point.y()), camera);
	m_rIndicatorTransform->setMatrix(osg::Matrix::translate(Snapping::snapPosition(p)));
}


osg::MatrixTransform* SquareIndicator::createIndicator()
{
	osg::MatrixTransform* transform = new osg::MatrixTransform;
	osg::Geode* geode = new osg::Geode;
	transform->addChild(geode);
	osg::ShapeDrawable* shapeDrawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0.05f), Units::squareSize(), Units::squareSize(), 0.1f));
	shapeDrawable->setColor(osg::Vec4(1,0,0,0.3));
	geode->addDrawable(shapeDrawable);

	return transform;
}
